//雇主详情完善信息
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:untitled1/app/res/myColors.dart';
import 'package:untitled1/app/utils/utilDialog.dart';
import 'package:untitled1/app/widgets/TitleBar.dart';
import 'package:untitled1/app/widgets/base_page/BaseStatefulPage.dart';


import '../../../bean/KeyValueBean.dart';
import '../../../utils/utilScreen.dart';
import '../../../widgets/TextSelector.dart';
import 'EmployerDetailUpdateController.dart';
import 'employer_page/employer_page_dialog/EmployerPageDialog.dart';

//完善信息
class EmployerDetailUpdate extends BaseStatefulPage {
  @override
  BaseStatefulPageState<BaseStatefulPage> createState() {
    return EmployerDetailUpdateState();
  }
}

class EmployerDetailUpdateState
    extends BaseStatefulPageState<EmployerDetailUpdate> {
  final EmployerDetailUpdateController controllerData = Get.put(
    EmployerDetailUpdateController(),
  );
  @override
  void initState() {
    super.initState();
    controllerData.initSelectData();
  }



  @override
  Widget buildPage(BuildContext context) {
    return Scaffold(
      appBar: TitleBar(title: "信息补全"),
      body: Container(
        color: myColors.c_bg,
        child: Column(
          children: [
            TextSelector(
              options: ['期望诉求', '基本信息', '过往信息', '经纪人评论'],
              onTap: (index) {
                print(">]index=${index}");
                WidgetsBinding.instance.addPostFrameCallback((_) {
                  controllerData.scrollTo(controllerData.titles[index]);
                });
              },
            ),
            Expanded(
              child: SingleChildScrollView(
                controller: controllerData.scrollController,
                child: Column(
                  children: [
                    buildTitle('期望诉求',controllerData.titles[0]),
                    Divider(height: 1, color: myColors.c_divider),
                    buildItem(
                      '诉求工种：',
                      controllerData.suqiugongzhong,
                      isRequired: true,
                      onTapFunction: () {
                        print('aaaaa');
                        EmployerPageDialog.dialog_gongzhong(context,controllerData?.keyValueBean?.value?.worktype_id?.valueList??[],(KeyValueBean bean){
                          controllerData.suqiugongzhong.value=bean;
                        });

                      },
                    ),
                    Divider(height: 1, color: myColors.c_divider),
                    buildItem(
                      '辅助工种：',
                      controllerData.fuzhugongzhong,
                      isRequired: false,
                      onTapFunction: () {
                        EmployerPageDialog.dialog_gongzhong(context,controllerData?.keyValueBean?.value?.worktype_ids?.valueList??[],(KeyValueBean bean){
                          controllerData.fuzhugongzhong.value=bean;
                        });
                      },
                    ),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItemTextField('辅助工种工作重点：', controllerData.zygznr),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItem(
                    //   '薪资类型：',
                    //   controllerData.xingbie,
                    //   isRequired: true,
                    //   onTapFunction: () {
                    //     controllerData.xingbie.value = '男';
                    //   },
                    // ),
                    Divider(height: 1, color: myColors.c_divider),
                    buildItem(
                      '薪酬：',
                      controllerData.xinchou,
                      isRequired: true,
                      onTapFunction: () {
                        EmployerPageDialog.dialog_gongzhong(context,controllerData?.keyValueBean?.value?.salary_type_id?.valueList??[],(KeyValueBean bean){
                          controllerData.xinchou.value=bean;
                        });
                      },
                    ),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItem(
                    //   '工作制度：',
                    //   controllerData.gongzuozhidu,
                    //   isRequired: true,
                    //   onTapFunction: () {
                    //     EmployerPageDialog.dialog_gongzhong(context,controllerData?.keyValueBean?.value?.salary_type_id?.valueList??[],(KeyValueBean bean){
                    //       controllerData.xinchou.value=bean;
                    //     });
                    //   },
                    // ),
                    Divider(height: 1, color: myColors.c_divider),
                    buildItem(
                      '工作属性：',
                      controllerData.gongzuoshuxing,
                      isRequired: true,
                      onTapFunction: () {
                            EmployerPageDialog.dialog_gongzhong(context,controllerData?.keyValueBean?.value?.worktime_type_id?.valueList??[],(KeyValueBean bean){
                              controllerData.gongzuoshuxing.value=bean;
                            });
                      },
                    ),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItem(
                    //   '服务时长：',
                    //   controllerData.xingbie,
                    //   isRequired: true,
                    //   onTapFunction: () {
                    //     controllerData.xingbie.value = '男';
                    //   },
                    // ),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItem(
                    //   '工作地点：',
                    //   controllerData.xingbie,
                    //   isRequired: true,
                    //   onTapFunction: () {
                    //     controllerData.xingbie.value = '男';
                    //   },
                    // ),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItemTextField('主要工作内容：', controllerData.zygznr),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItem(
                    //   '来源：',
                    //   controllerData.xingbie,
                    //   isRequired: true,
                    //   onTapFunction: () {
                    //     controllerData.xingbie.value = '男';
                    //   },
                    // ),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItem(
                    //   '分类：',
                    //   controllerData.xingbie,
                    //   isRequired: true,
                    //   onTapFunction: () {
                    //     controllerData.xingbie.value = '男';
                    //   },
                    // ),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItem(
                    //   '民族：',
                    //   controllerData.xingbie,
                    //   isRequired: false,
                    //   onTapFunction: () {
                    //     controllerData.xingbie.value = '男';
                    //   },
                    // ),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItem(
                    //   '宗教信仰：',
                    //   controllerData.xingbie,
                    //   isRequired: false,
                    //   onTapFunction: () {
                    //     controllerData.xingbie.value = '男';
                    //   },
                    // ),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItem(
                    //   '性别要求：',
                    //   controllerData.xingbie,
                    //   isRequired: false,
                    //   onTapFunction: () {
                    //     controllerData.xingbie.value = '男';
                    //   },
                    // ),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItem(
                    //   '年龄要求：',
                    //   controllerData.xingbie,
                    //   isRequired: false,
                    //   onTapFunction: () {
                    //     controllerData.xingbie.value = '男';
                    //   },
                    // ),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItem(
                    //   '学历要求：',
                    //   controllerData.xingbie,
                    //   isRequired: false,
                    //   onTapFunction: () {
                    //     controllerData.xingbie.value = '男';
                    //   },
                    // ),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItem(
                    //   '星座要求：',
                    //   controllerData.xingbie,
                    //   isRequired: false,
                    //   onTapFunction: () {
                    //     controllerData.xingbie.value = '男';
                    //   },
                    // ),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItem(
                    //   '属相要求：',
                    //   controllerData.xingbie,
                    //   isRequired: false,
                    //   onTapFunction: () {
                    //     controllerData.xingbie.value = '男';
                    //   },
                    // ),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItem(
                    //   '禁忌内容：',
                    //   controllerData.xingbie,
                    //   isRequired: true,
                    //   onTapFunction: () {
                    //     controllerData.xingbie.value = '男';
                    //   },
                    // ),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItem(
                    //   '福利：',
                    //   controllerData.xingbie,
                    //   isRequired: true,
                    //   onTapFunction: () {
                    //     controllerData.xingbie.value = '男';
                    //   },
                    // ),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItemTextField('其他福利：', controllerData.zygznr),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItem(
                    //   '面试时间：',
                    //   controllerData.xingbie,
                    //   isRequired: true,
                    //   onTapFunction: () {
                    //     controllerData.xingbie.value = '男';
                    //   },
                    // ),
                    // Divider(height: 1, color: myColors.c_divider),
                    //
                    // buildItem(
                    //   '入户时间：',
                    //   controllerData.xingbie,
                    //   isRequired: true,
                    //   onTapFunction: () {
                    //     controllerData.xingbie.value = '男';
                    //   },
                    // ),
                    // Divider(height: 10, color: myColors.c_divider),
                    // buildItem(
                    //   '语言要求：',
                    //   controllerData.xingbie,
                    //   isRequired: true,
                    //   onTapFunction: () {
                    //     controllerData.xingbie.value = '男';
                    //   },
                    // ),
                    // Divider(height: 10, color: myColors.c_divider),
                    //
                    //
                    // buildTitle('基本信息',controllerData.titles[1]),
                    //
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItem(
                    //   '姓名：',
                    //   controllerData.xingbie,
                    //   isRequired: false,
                    //   showArrow: false,
                    //   bgcolor: Color(0xffD1D3D5),
                    //   onTapFunction: () {
                    //     controllerData.xingbie.value = '男';
                    //   },
                    // ),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItem(
                    //   '籍贯：',
                    //   controllerData.xingbie,
                    //   isRequired: false,
                    //   onTapFunction: () {
                    //     controllerData.xingbie.value = '男';
                    //   },
                    // ),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItem(
                    //   '年龄：',
                    //   controllerData.xingbie,
                    //   isRequired: false,
                    //   onTapFunction: () {
                    //     controllerData.xingbie.value = '男';
                    //   },
                    // ),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItem(
                    //   '性别：',
                    //   controllerData.xingbie,
                    //   isRequired: false,
                    //   onTapFunction: () {
                    //     controllerData.xingbie.value = '男';
                    //   },
                    // ),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItem(
                    //   '属相：',
                    //   controllerData.xingbie,
                    //   isRequired: false,
                    //   onTapFunction: () {
                    //     controllerData.xingbie.value = '男';
                    //   },
                    // ),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItem(
                    //   '星座：',
                    //   controllerData.xingbie,
                    //   isRequired: false,
                    //   onTapFunction: () {
                    //     controllerData.xingbie.value = '男';
                    //   },
                    // ),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItem(
                    //   '民族：',
                    //   controllerData.xingbie,
                    //   isRequired: false,
                    //   onTapFunction: () {
                    //     controllerData.xingbie.value = '男';
                    //   },
                    // ),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItem(
                    //   '宗教信仰：',
                    //   controllerData.xingbie,
                    //   isRequired: false,
                    //   onTapFunction: () {
                    //     controllerData.xingbie.value = '男';
                    //   },
                    // ),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItem(
                    //   '居住地址：',
                    //   controllerData.xingbie,
                    //   isRequired: false,
                    //   onTapFunction: () {
                    //     controllerData.xingbie.value = '男';
                    //   },
                    // ),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItemTextField('详细地址：', controllerData.zygznr),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItem(
                    //   '意向度：',
                    //   controllerData.xingbie,
                    //   isRequired: false,
                    //   onTapFunction: () {
                    //     controllerData.xingbie.value = '男';
                    //   },
                    // ),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItem(
                    //   '类别：',
                    //   controllerData.xingbie,
                    //   isRequired: false,
                    //   onTapFunction: () {
                    //     controllerData.xingbie.value = '男';
                    //   },
                    // ),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItem(
                    //   '家庭情况：',
                    //   controllerData.xingbie,
                    //   isRequired: false,
                    //   onTapFunction: () {
                    //     controllerData.xingbie.value = '男';
                    //   },
                    // ),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItem(
                    //   '婚姻情况：',
                    //   controllerData.xingbie,
                    //   isRequired: false,
                    //   onTapFunction: () {
                    //     controllerData.xingbie.value = '男';
                    //   },
                    // ),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItem(
                    //   '老人情况：',
                    //   controllerData.xingbie,
                    //   isRequired: false,
                    //   onTapFunction: () {
                    //     controllerData.xingbie.value = '男';
                    //   },
                    // ),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItem(
                    //   '宠物情况：',
                    //   controllerData.xingbie,
                    //   isRequired: false,
                    //   onTapFunction: () {
                    //     controllerData.xingbie.value = '男';
                    //   },
                    // ),
                    //
                    // Divider(height: 10, color: myColors.c_divider),
                    //
                    //
                    // buildTitle('过往信息',controllerData.titles[2]),
                    // Divider(height: 1, color: myColors.c_divider),
                    // buildItem(
                    //   '曾聘请过几位服务人员：',
                    //   controllerData.xingbie,
                    //   isRequired: false,
                    //   showArrow: false,
                    //   bgcolor: Color(0xffD1D3D5),
                    //   onTapFunction: () {
                    //     controllerData.xingbie.value = '男';
                    //   },
                    // ),
                    Divider(height: 1, color: myColors.c_divider),
                    buildItemTextField('您认可的服务人员在哪些方面最吸引您:', controllerData.zygznr),
                    Divider(height: 1, color: myColors.c_divider),
                    buildItemTextField('您最忌讳掩盖服务人员的哪些行为:', controllerData.zygznr),
                    Divider(height: 1, color: myColors.c_divider),
                    buildItemTextField('与前任服务人员解除合作的原因是什么:', controllerData.zygznr),
                    Divider(height: 1, color: myColors.c_divider),
                    buildItemTextField('分别在哪个企业机构雇用的服务人员:', controllerData.zygznr),
                    buildTitle('经纪人评论',controllerData.titles[3]),
                    Divider(height: 1, color: myColors.c_divider),
                    Container(
                      color: myColors.white,
                      padding: EdgeInsets.only(left: 15, right: 15, top: 10, bottom: 10),
                      child: SizedBox(
                        height: 60,
                        width: utilScreen.getScreenWidth(context),
                        child: TextField(
                          controller: controllerData.controller_glypl,
                          style: TextStyle(fontSize: 14, color: myColors.c_191919),
                          maxLines: null, // 没有限制行数 → 自动换行
                          decoration: InputDecoration(
                            hintText: '请输入内容', // 设置提示语
                            border: InputBorder.none, // 移除所有边框
                          ),
                          onChanged: (text) {

                          },
                        ),
                      ),
                    )


                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  // 头像组件
  Widget buildTitle(String title,GlobalKey key) {
    return Container(
      key:key ,
      alignment: Alignment.centerLeft,
      height: 40,
      margin: const EdgeInsets.symmetric(horizontal: 15),
      child: Text(
        title,
        style: TextStyle(color: myColors.c_191919, fontWeight: FontWeight.bold),
      ),
    );
  }

  // 通用信息项
  Widget buildItem(
    String title,
    Rx<KeyValueBean> bean, {
    bool showArrow = true,
    int maxLines = 1,
    bool isRequired = false, Color bgcolor = Colors.white,
    Function()? onTapFunction,
  }) {
    return Obx(
      () => Container(
        color:bgcolor,
        padding: const EdgeInsets.symmetric(vertical: 0),
        child: ListTile(
          title: Row(
            children: [
              if (isRequired)
                Text(
                  "*",
                  style: TextStyle(
                    color: Colors.red,
                    fontSize: 12,
                    fontWeight: FontWeight.bold,
                  ),
                ),
              Text(
                title,
                style: const TextStyle(fontSize: 14, color: myColors.c_191919),
              ),
            ],
          ),
          trailing: Row(
            mainAxisSize: MainAxisSize.min,
            children: [
              if (bean.value != null)
                Text(
                  bean.value.value?? '',
                  maxLines: maxLines,
                  overflow: TextOverflow.ellipsis,
                  style: const TextStyle(color: Colors.black),
                ),
              if (showArrow) const SizedBox(width: 10),
              if (showArrow) const Icon(Icons.arrow_forward_ios, size: 16),
            ],
          ),
          onTap: () {
            if (onTapFunction == null) {
              return;
            }
            // setState(() {
            onTapFunction();
            print('>]aaaaaaa  value=${bean.value.value}');
            // });
          },
        ),
      ),
    );
  }

  Widget buildItemTextField(String title, RxString value) {
    final TextEditingController _controller = TextEditingController(text: value.value);
    return Container(
      color: myColors.white,
      padding: EdgeInsets.only(left: 15, right: 15, top: 10, bottom: 10),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            title,
            style: const TextStyle(fontSize: 14, color: myColors.c_191919),
          ),
          SizedBox(
            height: 60,
            width: utilScreen.getScreenWidth(context),
            child: TextField(
              controller: _controller, // 控制器绑定
              style: TextStyle(fontSize: 14, color: myColors.c_191919),
              maxLines: null, // 没有限制行数 → 自动换行
              decoration: InputDecoration(
                hintText: '请输入内容', // 设置提示语
                border: InputBorder.none, // 移除所有边框
              ),
              onChanged: (text) {
                value.value=text;
              },
            ),
          ),
        ],
      ),
    );
  }
}
